#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
#else
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
#endif

namespace Microsoft.Practices.EnterpriseLibrary.Validation.Tests
{
	[TestClass]
	public class ValidationExceptionFixture 
	{
		[TestMethod]
		public void ShouldNotThrowIfResultsIsValid()
		{
			ValidationResults results = new ValidationResults();

			new ValidationException(results);
		}

		[TestMethod]
		public void ShouldEmptyMessageIfResultsIsValid()
		{
			ValidationResults results = new ValidationResults();

			string message = new ValidationException(results).Message;

			Assert.AreEqual(0, message.Length);
		}

		[TestMethod]
		public void ShouldAccumulateMessages()
		{
			ValidationResult res1 = new ValidationResult("foo", null, "", "", null);
			ValidationResult res2 = new ValidationResult("bar", null, "", "", null);

			ValidationResults results = new ValidationResults();
			results.AddResult(res1);
			results.AddResult(res2);

			ValidationException ex = new ValidationException(results);

			Assert.AreEqual("foo\r\nbar\r\n", ex.Message);
		}

		[TestMethod]
		public void ShouldExposeResults()
		{
			ValidationResult res1 = new ValidationResult("foo", null, "", "", null);
			ValidationResult res2 = new ValidationResult("bar", null, "", "", null);

			ValidationResults results = new ValidationResults();
			results.AddResult(res1);
			results.AddResult(res2);

			ValidationException ex = new ValidationException(results);

			Assert.AreSame(results, ex.ValidationResults);
		}
	}
}
